import { ref, computed } from "vue";
import { defineStore } from "pinia";

export const useUserStore = defineStore(
  "user",
  () => {
    const user = ref({
      adminUsername: "test",
      identity: "管理员",
      adminId: 1,
      exp: 1724929318,
      token:
        "eyJhbGciOiJIUzI1NiJ9.eyJhZG1pblVzZXJuYW1lIjoiYWRtaW4iLCJpZGVudGl0eSI6IueuoeeQhuWRmCIsImFkbWluSWQiOjEsImV4cCI6MTcyNDkyOTMxOH0.gQSQF78VIrvb86cp5-5CXvc6K-C4kiNLoOHfmKZQygQ",
    });

    const setUserInfo = (data: any) => {
      user.value = data;
    };

    const getUserInfo = () => {
      return user.value;
    };

    return {
      user,
      setUserInfo,
      getUserInfo,
    };
  },
  {
    persist: {
      storage: localStorage,
    },
  }
);
